package com.biyu.monitormanage.controller;

import com.biyu.monitormanage.common.annotation.SysLog;
import com.biyu.monitormanage.common.utils.BaseResponse;
import com.biyu.monitormanage.common.utils.PageUtils;
import com.biyu.monitormanage.entity.MonitorEntity;
import com.biyu.monitormanage.entity.PoliceEntity;
import com.biyu.monitormanage.service.PoliceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @author 15491
 */
@RestController
@RequestMapping("/monitormanage/police")
public class PoliceController {

    private final PoliceService policeService;

    @Autowired
    public PoliceController(PoliceService policeService) {
        this.policeService = policeService;
    }

    /**
     * 列表
     */
    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("monitormanage:police:list")
    public BaseResponse list(@RequestParam Map<String, Object> params){
        PageUtils page = policeService.queryPage(params);

        return BaseResponse.ok().put("page", page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("monitormanage:police:info")
    public BaseResponse info(@PathVariable("id") Long id){
        PoliceEntity policeEntity = policeService.getById(id);

        return BaseResponse.ok().put("user", policeEntity);
    }

    /**
     * 保存
     */
    @SysLog("新增报警设置")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @RequiresPermissions("monitormanage:police:save")
    public BaseResponse save(@RequestBody PoliceEntity police){
        policeService.save(police);

        return BaseResponse.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改报警设置")
    @RequestMapping("/update")
    @RequiresPermissions("monitormanage:police:update")
    public BaseResponse update(@RequestBody PoliceEntity police){
        policeService.updateById(police);
        return BaseResponse.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除报警信息")
    @RequestMapping("/delete")
    @RequiresPermissions("monitormanage:police:delete")
    public BaseResponse delete(@RequestBody Long[] ids){
        policeService.removeByIds(Arrays.asList(ids));

        return BaseResponse.ok();
    }
}
